package com.brother.util;

import com.brother.model.LatLngPoint;

public class Distance {
	
	
/**get distance as meter
 * @param from
 * @param to
 * @return
 */
public static double distance(LatLngPoint from , LatLngPoint to){
//	R = earth’s radius (mean radius = 6,371km)
//	Δlat = lat2− lat1
//	Δlong = long2− long1
//	a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
//	c = 2.atan2(√a, √(1−a))
//	d = R.c 
	

//	var R = 6371; // km
//	var dLat = (lat2-lat1).toRad();
//	var dLon = (lon2-lon1).toRad(); 
//	var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
//	        Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * 
//	        Math.sin(dLon/2) * Math.sin(dLon/2); 
//	var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
//	var d = R * c;
	
int r = 6371000;
double dLat = (to.getLat() - from.getLat()) / 180 * Math.PI;
double dLng = (to.getLng() - from.getLng()) / 180 * Math.PI;
double a = Math.sin(dLat/2) * Math.sin(dLat/2) + 
	Math.cos(from.getLat() / 180 *Math.PI) * Math.cos(to.getLat() / 180 *Math.PI)*
	Math.sin(dLng/2) * Math.sin(dLng/2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
double d = r * c;
	
return d;

	


}
}
